﻿
/*=========================================
* Author: Administrator
* DateTime:2017/6/20 19:20:37
* Description:$safeprojectname$
==========================================*/

using System;
using System.Collections.Generic;
using PureMVC.Interfaces;
using PureMVC.Patterns;
using UnityEngine;

namespace OrderSystem
{
    public class ClientMediator : Mediator
    {
        public new const string NAME = "ClientMediator";
        public ClientItemView itemView;
        
        private ClientView View
        {
            get { return (ClientView)ViewComponent; }
        }

        public ClientMediator( ClientView view ) : base(NAME , view)
        {
            Debug.Log("ClientMediator程序启动");
            view.PayWaiter += (ClientItem item) => {
                //不应该让midiator之间进行通信。   
                SendNotification(ClientEvent.CLIENT_PAY_TO_WAITER, item);
            };

            view.CallWaiter += data =>
            {
                if(data!=null)
                {
                    Debug.Log("2.叫服务员拿菜单过来");
                    SendNotification(ClientEvent.CLIENT_CALL_WAITER, data);
                }
                else
                {
                    Debug.LogError("Data Not Found!!!!!!!!!!!!!!!!");
                }
            };

            view.LeaveClient += (ClientItem item) =>
            {
                SendNotification(ClientEvent.CLIENT_LEAVE, item);
            };

            
        }

        public override void OnRegister()
        {
            base.OnRegister();

            SendNotification(ClientEvent.GET_CLIENT_LIST);
        }

        public override IList<string> ListNotificationInterests()
        {
            IList<string> notifications = new List<string>();
            notifications.Add(OrderSystemEvent.PAY); 
            notifications.Add(ClientEvent.GET_CLIENT_LIST_BACK);
            notifications.Add(ClientEvent.UPDATE_STRAT_EATING_STATE);
           // notifications.Add(ClientEvent.CLIENT_PAY_TO_WAITER);

            notifications.Add(ClientEvent.UPDATE_CLIENT_FINISH_PAY);
            return notifications;
        }

        public override void HandleNotification(INotification notification)
        {
            switch (notification.Name)
            {
                case ClientEvent.UPDATE_STRAT_EATING_STATE:
                    //饭菜上桌，客人进入就餐状态。
                    View.UpdateClient(notification.Body as IList<ClientItem>);                    
                    break;
             //   case ClientEvent.CLIENT_PAY_TO_WAITER:
             //       //付款状态，发消息给服务员进入空闲状态
             //       Debug.Log("结账给服务员");
             //       SendNotification(OrderSystemEvent.GET_PAY,notification.Body);
             //       break;
                case ClientEvent.UPDATE_CLIENT_FINISH_PAY:
                    //付款走人 进入离店状态。位置空出来进入idel状态。
                    Debug.Log("离店回到空桌子状态");
                    View.UpdateClient(notification.Body as IList<ClientItem>);
                    break;
                case ClientEvent.GET_CLIENT_LIST_BACK:
                     View.UpdateClient(notification.Body as IList<ClientItem>);     
                    break;

            }
        }
    }
}